//
//  FriendNewDetailsViewController.m
//  CheekiOS
//
//  Created by mac on 2017/6/12.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "FriendNewDetailsViewController.h"


#import "UITableView+SDAutoTableViewCellHeight.h"
#import "SDTimeLineCellModel.h"

#import <AVFoundation/AVFoundation.h>
#import "FriendNewTableViewCell.h"
#import "HomeStrangCollionViewController.h"


@interface FriendNewDetailsViewController ()<UITableViewDelegate, UITableViewDataSource, FriendNewTableViewCellDelegate, CAAnimationDelegate, RCEmojiViewDelegate,RCChatSessionInputBarControlDelegate,UITextViewDelegate>{
    

}

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dataArray;

@property (nonatomic, retain) RCChatSessionInputBarControl *chetctr;



//点赞
@property (nonatomic, assign) NSInteger trystId;
//视频播放
@property (nonatomic, strong) AVPlayer *player ;
@property (nonatomic, strong) AVPlayerLayer *playerLayer ;
@property (nonatomic, strong) UIView *PlayerView;
//回复
@property (nonatomic, copy  ) NSString *commentToUser;
@property (nonatomic, strong) UILabel *labCommentId;
@property (nonatomic, strong) NSString *CommentIdStr;
@property (nonatomic, strong) NSString *CommentStrList;
@property (nonatomic, strong) NSString *CommentUserId;
@property (nonatomic, strong) NSString *CommentKeybord;
@property (nonatomic, strong) NSIndexPath *selectIndexPath;
//键盘
@property (nonatomic, assign) CGRect keyboardR;
@property (nonatomic, assign) CGFloat y;
@property (nonatomic, strong) UITextView *textViewV;
@property (nonatomic, strong) NSString *strIndexPath;

@end
#define FriendtimeNewLineIdent @"FriendtimeNewLineIdent"

@implementation FriendNewDetailsViewController

-(void)viewWillAppear:(BOOL)animated{
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc]init]];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor blackColor], NSFontAttributeName : FontP(18)};
    self.navigationController.navigationBar.barTintColor = Colorbackground;
    [self.navigationController.navigationBar setTranslucent:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
    if (!_tableView) {
        _tableView = [[UITableView alloc] init];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.view);
            make.top.equalTo(self.view).offset(0);
            make.height.equalTo(self.view).offset(-50);
        }];
    }
    [self.tableView registerClass:[FriendNewTableViewCell class] forCellReuseIdentifier:FriendtimeNewLineIdent];

    [self requestData];
    
    
    _chetctr = [[RCChatSessionInputBarControl alloc] initWithFrame:CGRectMake(0, KScreenHeight-114, KScreenWidth, 50) withContainerView:self.view controlType:RCChatSessionInputBarControlDefaultType controlStyle:RC_CHAT_INPUT_BAR_STYLE_CONTAINER defaultInputType:RCChatSessionInputBarInputText];
    _chetctr.delegate=self;
    _chetctr.inputTextView.delegate = self;
    [self.view addSubview:_chetctr];
    
    
}
- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    self.tableView.contentInset = UIEdgeInsetsZero;
    self.tableView.scrollIndicatorInsets = UIEdgeInsetsZero;
}

- (void)requestData{
    
  [HQHttpManager FriendNewhistoryCircleId:_CircleId successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
             if (isSuccess) {
                 NSDictionary *dic = resultDic[@"res"];
                     HRTimeLineModel *model = [HRTimeLineModel getTimeLineModelWithDictionary:dic];
                     [self.dataArray addObject:model];
                 [_tableView reloadData];
             }
        }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HRTimeLineModel *timeLineModel = self.dataArray[indexPath.row];
    Active *model = [Active getActiveWithDictionary:(NSDictionary *)timeLineModel.active];
    
    FriendNewTableViewCell *cell = [FriendNewTableViewCell cellWithTableView:tableView indexPath:indexPath];
    cell.styleStr = @"1";
    cell.indexPath = indexPath;
    __weak typeof(self) weakSelf = self;
    
    
   
    
    [cell setFriendNewmoreButtonClickedBlock:^(NSIndexPath *indexPath){
        SDTimeLineCellModel *model = weakSelf.dataArray[indexPath.row];
        model.isOpening = !model.isOpening;
        [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];

    }];
    
    [cell setFriendNewdidClickCommentLabelBlock:^(NSString *commentId, CGRect rectInWindow, NSIndexPath *indexPath,NSString *username){
        _CommentKeybord = @"1";
        
        self.chetctr.hidden = NO;
        [self.chetctr.inputTextView becomeFirstResponder];
        _labCommentId= [[UILabel alloc] init];
        _labCommentId.text =[NSString stringWithFormat:@"回复: %@ ",username];
        _CommentUserId = @"";
        _CommentUserId = commentId;
        _CommentIdStr = @"";
        _CommentIdStr = username;
        _labCommentId.enabled = NO;
        _labCommentId.backgroundColor = [UIColor whiteColor];
        _labCommentId.frame = CGRectMake(0, 0, KScreenWidth, self.chetctr.inputTextView.height);
        _selectIndexPath = indexPath;
        [self.chetctr.inputTextView addSubview:_labCommentId];
        

    }];
    
   
    
    cell.delegate = self;
    
    [cell useCellFrameCacheWithIndexPath:indexPath tableView:tableView];
    
    cell.model = model;
    
    
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HRTimeLineModel *timeLineModel = self.dataArray[indexPath.row];
    
    Active *model = [Active getActiveWithDictionary:(NSDictionary *)timeLineModel.active];
    
    return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[FriendNewTableViewCell class] contentViewWidth:[self cellContentViewWith]];
    
}

- (CGFloat)cellContentViewWith {
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    
    // 适配ios7
    if ([UIApplication sharedApplication].statusBarOrientation != UIInterfaceOrientationPortrait && [[UIDevice currentDevice].systemVersion floatValue] < 8) {
        width = [UIScreen mainScreen].bounds.size.height;
    }
    return width;
}
- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
- (void)FriendNewdidClickLikeButtonInCell:(UITableViewCell *)cell opertionStr:(NSString *)opertionStr
{
    NSIndexPath *index = [self.tableView indexPathForCell:cell];
    NSLog(@"...");
    NSInteger Typeteger ;
    if ([opertionStr isEqualToString:@"赞"]) {
        Typeteger =1;
    }else{
        Typeteger = 2;
    }
    
    HRTimeLineModel *timeLineModel = self.dataArray[index.row];
    Active *model = [Active getActiveWithDictionary:(NSDictionary *)timeLineModel.active];
    _trystId = model.trystId;
    
    
    [HQHttpManager addPraiseWithUid:[HQHttpManager getUserId] circleId:[_CircleId integerValue] trystId:_trystId type:Typeteger successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
        if (isSuccess) {
            NSString *uid = [HQHttpManager getUserId];
            NSDictionary *PraiseDic = @{@"uid":@(uid.integerValue),@"nickName":[HQHttpManager userNickName]};
            NSDictionary *active1 = (NSDictionary *)timeLineModel.active;
            NSMutableDictionary *active = active1.mutableCopy;
            NSArray *praiseList = @[];
            
            NSMutableArray *array = @[].mutableCopy;
            
            if (active[@"praiseList"] != nil) {
                praiseList = active[@"praiseList"];
                array = praiseList.mutableCopy;
            }
            
            
            
            if (Typeteger  == 1) {
                
                [array addObject:PraiseDic];
                [active setValue:array forKey:@"praiseList"];
                
                timeLineModel.active = active.mutableCopy;
            }else{
                
                for (NSDictionary * dic in praiseList) {
                    if ([dic[@"nickName"] isEqualToString:PraiseDic[@"nickName"]] && [dic[@"uid"] isEqualToNumber:PraiseDic[@"uid"]]) {
                        [array removeObject:dic];
                    }
                }
                [active setValue:array forKey:@"praiseList"];
                NSLog(@"%@",PraiseDic);
                
                timeLineModel.active = active.mutableCopy;
                
            }
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:index,nil] withRowAnimation:UITableViewRowAnimationNone];
            });
        }
    }];
    
    

}


- (void)FriendNewdidClickcCommentButtonInCell:(UITableViewCell *)cell{
    
    _strIndexPath = @"1";
    NSLog(@"评论被点击");
    NSIndexPath *index = [self.tableView indexPathForCell:cell];
    HRTimeLineModel *timeLineModel = self.dataArray[index.row];
    Active *model = [Active getActiveWithDictionary:(NSDictionary *)timeLineModel.active];
    _selectIndexPath = index;
    _trystId = model.trystId;
    _CircleId = [NSString stringWithFormat:@"%ld",model.circleId];
    self.chetctr.hidden = NO;
    [self.chetctr.inputTextView becomeFirstResponder];

    

}

- (void)FriendNewdidClickIconInCell:(UITableViewCell *)cell{

    NSIndexPath *index = [self.tableView indexPathForCell:cell];
    HRTimeLineModel *timeLineModel = self.dataArray[index.row];
    Active *model = [Active getActiveWithDictionary:(NSDictionary *)timeLineModel.active];
    HomeStrangCollionViewController *UDIVC = [[HomeStrangCollionViewController alloc] init];
    
    
    UDIVC.navigationController.navigationBar.hidden = YES;
    
    
    UDIVC.UserId = [NSString stringWithFormat:@"%ld",(long)model.uid] ;
    [self.navigationController pushViewController:UDIVC animated:YES];
}

//删除动态
- (void)FriendNewdidClickDeleteInCell:(UITableViewCell *)cell{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"确定要删除这条状态吗" message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *confirAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSIndexPath *index = [self.tableView indexPathForCell:cell];
        HRTimeLineModel *timeLineModel = self.dataArray[index.row];
        Active *model = [Active getActiveWithDictionary:(NSDictionary *)timeLineModel.active];
        [HQHttpManager delActiveWithUid:[HQHttpManager getUserId] circleId:model.circleId trystId:model.trystId successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
            if (isSuccess) {

                [self.dataArray removeObject:timeLineModel];
                [self.tableView reloadData];
            }
        }];
        
    }];
    UIAlertAction *cliceAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertVC addAction:confirAction];
    [alertVC addAction:cliceAction];
    [self.navigationController presentViewController:alertVC animated:YES completion:nil];
    

}
-(void)UserEditDeleteInCell:(UITableViewCell *)cell{

        NSIndexPath *index = [self.tableView indexPathForCell:cell];
        HRTimeLineModel *timeLineModel = self.dataArray[index.row];
        Active *model = [Active getActiveWithDictionary:(NSDictionary *)timeLineModel.active];
        [HQHttpManager delActiveWithUid:[HQHttpManager getUserId] circleId:model.circleId trystId:model.trystId successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
            if (isSuccess) {
                
                [self.dataArray removeObject:timeLineModel];
                [self.tableView reloadData];
                //通知 个人修改信息界面 刷新状态信息
                [[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationUserstateRequestAction" object:nil];
                
                
                [self.navigationController popViewControllerAnimated:YES];
            }
        }];

}
- (void)FriendNewdidClickPlayButton:(NSString *)url {
    
    _PlayerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    _PlayerView.backgroundColor = [UIColor blackColor];
    
    CABasicAnimation *animation = nil;
    //缩放
    animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    [animation setFromValue:@0.1];//设置起始值
    [animation setToValue:@1.];//设置目标值
    [animation setDelegate:self];//代理回调
    [animation setDuration:0.3];//设置动画时间，单次动画时间
    [animation setRemovedOnCompletion:NO];
    
    //you view need to replace
    [_PlayerView.layer addAnimation:animation forKey:nil];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = _PlayerView.frame;
    [btn addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
    
    CGFloat Height = KScreenWidth/4*3;
    AVPlayerItem *item = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:HttpImgUrl(url)]];
    AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:item];
    AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer: player];
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    playerLayer.frame = CGRectMake(0, -64, KScreenWidth, Height+64);
    playerLayer.position = self.view.center;
    
    [_PlayerView.layer addSublayer: playerLayer];
    [playerLayer setNeedsDisplay];
    
    [player play];
    
    self.player = player;
    
    _playerLayer = playerLayer;
    
    self.view.backgroundColor = [UIColor blackColor];
    __weak typeof(self) weakSelf = self;
    NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter];
    [noteCenter addObserverForName:AVPlayerItemDidPlayToEndTimeNotification
                            object:nil
                             queue:nil
                        usingBlock:^(NSNotification *note) {
                            [weakSelf.player seekToTime:kCMTimeZero];
                            [weakSelf.player play];
                        }];
    [_PlayerView addSubview:btn];
    [self.view.window addSubview:_PlayerView];
    
}

- (void)backButtonClick{
    [_player pause];
    _player = nil;
    CABasicAnimation *animation = nil;
    //缩放
    animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    [animation setFromValue:@1.0f];//设置起始值
    [animation setToValue:@0.1f];//设置目标值
    [animation setDelegate:self];//代理回调
    [animation setDuration:0.3f];//设置动画时间，单次动画时间
    [animation setRemovedOnCompletion:NO];
    
    //you view need to replace
    [_PlayerView.layer addAnimation:animation forKey:nil];
    
    [UIView animateWithDuration:0.3f animations:^{
        
        
    } completion:^(BOOL finished) {
        
        [self.view.window removeFromSuperview];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            _PlayerView.hidden = YES;
            
            [_PlayerView removeFromSuperview];
        });
        
    }];
    
    
}


//评论  回复评论请求方法   输入方法
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    
    
    if ([_CommentKeybord isEqualToString:@"1"]) {
        _labCommentId.hidden = YES;
        _CommentStrList = @"1";
        
    }else{
        _labCommentId.hidden = NO;
        
    }
    
    
    
    WEAKSELF
    
    if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车，即按下return
        NSLog(@"text=%@",textView.text);
        NSLog(@"点击键盘确认");
        [self.chetctr updateStatus:KBottomBarDefaultStatus animated:YES];
        [self.view endEditing:YES];
        [UIView beginAnimations:@"Animation" context:nil];
        [UIView setAnimationDuration:0.10];
        [UIView setAnimationBeginsFromCurrentState: YES];
        self.chetctr.frame = CGRectMake(0, KScreenHeight-114, KScreenWidth, 50);
        [UIView commitAnimations];
        self.chetctr.hidden = NO;
        HRTimeLineModel *timeLineModel = self.dataArray[_selectIndexPath.row];
        NSString *contentString = _chetctr.inputTextView.text;
        
        if ([_CommentStrList isEqualToString:@"1"]) {
            
            [HcardHttpmanager CommentreplyUid:[HQHttpManager getUserId] content:_chetctr.inputTextView.text replyId:_CommentUserId.integerValue circleId:[_CircleId integerValue] trystId:_trystId Success:^(id result) {
                
                NSString *uid = [HQHttpManager getUserId];
                NSDictionary *CommentDic = @{@"uid":@(uid.integerValue),@"nickName":[HQHttpManager userNickName],@"content":contentString,@"toNickName":_CommentIdStr,@"replyId":_CommentUserId,@"circleId":_CircleId};
                
                
                NSDictionary *active1 = (NSDictionary *)timeLineModel.active;
                NSMutableDictionary *active = active1.mutableCopy;
                NSArray *commentlist = @[];
                NSMutableArray *array = @[].mutableCopy;
                if (active[@"commentList"] != nil) {
                    commentlist = active[@"commentList"];
                    array = commentlist.mutableCopy;
                }
                [array addObject:CommentDic];
                [active setValue:array forKey:@"commentList"];
                timeLineModel.active = active.mutableCopy;
                [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:_selectIndexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
                weakSelf.chetctr.inputTextView.text = @"";
                
            } failure:^(NSError *error) {
                
                
                
            }];
            _CommentStrList = @"0";
            _CommentKeybord = @"0";
        }else{
            [HQHttpManager addCommentWithUid:[HQHttpManager getUserId] circleId:[_CircleId integerValue] trystId:_trystId content:_chetctr.inputTextView.text successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
                if (isSuccess) {
                    NSString *uid = [HQHttpManager getUserId];
                    NSDictionary *CommentDic = @{@"uid":@(uid.integerValue),@"nickName":[HQHttpManager userNickName],@"content":contentString};
                    NSDictionary *active1 = (NSDictionary *)timeLineModel.active;
                    NSMutableDictionary *active = active1.mutableCopy;
                    NSArray *commentlist = @[];
                    NSMutableArray *array = @[].mutableCopy;
                    if (active[@"commentList"] != nil) {
                        commentlist = active[@"commentList"];
                        array = commentlist.mutableCopy;
                    }
                    [array addObject:CommentDic];
                    [active setValue:array forKey:@"commentList"];
                    timeLineModel.active = active.mutableCopy;
                    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:_selectIndexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
                    weakSelf.chetctr.inputTextView.text = @"";
                }
            }];
            weakSelf.chetctr.inputTextView.text = @"";
            //在这里做你响应return键的代码
            return NO; //这里返回NO，就代表return键值失效，即页面上按下return，不会出现换行，如果为yes，则输入页面会换行
            
        }
    }
    
    return YES;
}

- (void)inputTextView:(UITextView *)inputTextView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    //    [_chetctr updateStatus:KBottomBarKeyboardStatus animated:YES];
}

- (void)inputTextViewDidTouchSendKey:(UITextView *)inputTextView {
    NSLog(@"text=%@",inputTextView.text);
    NSLog(@"点击键盘确认");
}

- (void)didTouchKeyboardReturnKey:(RCChatSessionInputBarControl *)inputControl text:(NSString *)text {
    //self.textview.text=text;
    NSLog(@"text=%@",text);
    NSLog(@"点击键盘确认");
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.chetctr updateStatus:KBottomBarDefaultStatus animated:NO  ];
    [self.view endEditing:YES];
    [UIView beginAnimations:@"Animation" context:nil];
    [UIView setAnimationDuration:0.10];
    [UIView setAnimationBeginsFromCurrentState: YES];
    self.chetctr.frame = CGRectMake(self.chetctr.frame.origin.x, KScreenWidth-114, self.chetctr.frame.size.width, self.chetctr.frame.size.height);
    
    self.chetctr.hidden = YES;
    [UIView commitAnimations];


}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == _tableView) {
        [self.chetctr updateStatus:KBottomBarDefaultStatus animated:NO];
        [self.view endEditing:YES];
        self.chetctr.frame = CGRectMake(self.chetctr.frame.origin.x, KScreenHeight-114, self.chetctr.frame.size.width, self.chetctr.frame.size.height);
        self.chetctr.hidden = NO;
    }
}

- (void)keyboardWillShow:(NSNotification *)note{
    [self.view bringSubviewToFront:self.chetctr];
    CGRect keyboardBounds;
    [[note.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];
    keyboardBounds = [self.view convertRect:keyboardBounds toView:nil];
    if (self.chetctr.frame.origin.y == KScreenHeight-50-keyboardBounds.size.height) {
        return;
    }
    [UIView beginAnimations:@"Animation" context:nil];
    [UIView setAnimationDuration:0.10];
    [UIView setAnimationBeginsFromCurrentState: YES];
    self.chetctr.frame = CGRectMake(self.chetctr.frame.origin.x, KScreenHeight - self.chetctr.frame.size.height - keyboardBounds.size.height-64, self.chetctr.frame.size.width, self.chetctr.frame.size.height);
    _y = self.chetctr.frame.origin.y - keyboardBounds.size.height;
    
    
    [UIView commitAnimations];
}

- (void)keyboardWillHide:(NSNotification *)note{
    if (self.view.frame.origin.y==0) {
        return;
    }
    [UIView beginAnimations:@"Animation" context:nil];
    [UIView setAnimationDuration:0.10];
    [UIView setAnimationBeginsFromCurrentState: YES];
    self.chetctr.frame = CGRectMake(0, KScreenHeight-114, KScreenWidth, 50);
    [UIView commitAnimations];
    self.chetctr.hidden = NO;
    
}
- (RCChatSessionInputBarControl *)chetctr {
    if (!_chetctr) {
        _chetctr = [[RCChatSessionInputBarControl alloc] initWithFrame:CGRectMake(0, KScreenHeight-114, KScreenWidth, 50) withContainerView:self.view controlType:RCChatSessionInputBarControlDefaultType controlStyle:RC_CHAT_INPUT_BAR_STYLE_CONTAINER defaultInputType:RCChatSessionInputBarInputText];
        _chetctr.delegate=self;
        _chetctr.inputTextView.delegate = self;
        [self.view addSubview:_chetctr];
    }
    return _chetctr;
}

#pragma RCEmojiViewDelegate-------

/**
 *  didTouchEmojiView
 *
 *  @param emojiView emojiView
 *  @param sendButton    string
 */

- (void)emojiView:(RCEmojiBoardView *)emojiView didTouchSendButton:(UIButton *)sendButton {
    NSLog(@"inputTextView=%@",self.chetctr.inputTextView.text);
    [self.chetctr updateStatus:KBottomBarDefaultStatus animated:YES];
    [self.view endEditing:YES];
    [UIView beginAnimations:@"Animation" context:nil];
    [UIView setAnimationDuration:0.10];
    [UIView setAnimationBeginsFromCurrentState: YES];
    self.chetctr.frame = CGRectMake(self.chetctr.frame.origin.x, KScreenHeight, self.chetctr.frame.size.width, self.chetctr.frame.size.height);
    [UIView commitAnimations];
    HRTimeLineModel *timeLineModel = self.dataArray[_selectIndexPath.row];
    NSString *contentString = _chetctr.inputTextView.text;
    WEAKSELF
    [HQHttpManager addCommentWithUid:[HQHttpManager getUserId] circleId:[_CircleId integerValue] trystId:_trystId content:_chetctr.inputTextView.text successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
        if (isSuccess) {
            NSString *uid = [HQHttpManager getUserId];
            NSDictionary *CommentDic = @{@"uid":@(uid.integerValue),@"nickName":[HQHttpManager userNickName],@"content":contentString};
            NSDictionary *active1 = (NSDictionary *)timeLineModel.active;
            NSMutableDictionary *active = active1.mutableCopy;
            NSArray *commentlist = @[];
            NSMutableArray *array = @[].mutableCopy;
            if (active[@"commentList"] != nil) {
                commentlist = active[@"commentList"];
                array = commentlist.mutableCopy;
            }
            [array addObject:CommentDic];
            [active setValue:array forKey:@"commentList"];
            timeLineModel.active = active.mutableCopy;
            [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:_selectIndexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
            weakSelf.chetctr.inputTextView.text = @"";
        }
    }];
    weakSelf.chetctr.inputTextView.text = @"";
}

- (void)didTouchEmojiView:(RCEmojiBoardView *)emojiView touchedEmoji:(NSString *)string {
    NSLog(@"text=%@",string);
}
- (void)emojiView:(RCEmojiBoardView *)emojiView didTouchedEmoji:(NSString *)touchedEmoji {
    NSLog(@"text=%@",touchedEmoji);
    
}

/**
 *  didSendButtonEvent
 *
 *  @param emojiView  emojiView
 *  @param sendButton send button
 */
- (void)didSendButtonEvent:(RCEmojiBoardView *)emojiView sendButton:(UIButton *)sendButton{
    
}

- (void)chatInputBar:(RCChatSessionInputBarControl *)chatInputBar shouldChangeFrame:(CGRect)frame {
    
    if (chatInputBar.currentBottomBarStatus == KBottomBarDefaultStatus||chatInputBar.currentBottomBarStatus == KBottomBarKeyboardStatus ||chatInputBar.currentBottomBarStatus == KBottomBarEmojiStatus) {
        
        if (chatInputBar.currentBottomBarStatus ==KBottomBarDefaultStatus) {
            self.chetctr.frame = frame ;
            
            self.chetctr.hidden = NO;
            [self.view bringSubviewToFront:self.chetctr];
            _keyboardR = self.chetctr.frame;
            
            if ([_CommentKeybord isEqualToString:@"1"]) {
                _labCommentId.hidden = YES;
            }
            
        }else{
            self.chetctr.frame = _keyboardR ;
            self.chetctr.hidden = NO;
            [self.view bringSubviewToFront:self.chetctr];
            
        }
        
        return ;
    }
    self.chetctr.frame = frame;
    [self.view bringSubviewToFront:self.chetctr];
    
}

- (void)presentViewController:(UIViewController *)viewController functionTag:(NSInteger)functionTag {
    
}

- (void)chatSessionInputBarControlContentSizeChanged:(CGRect)frame {
    CGRect ViewRect = self.view.frame;
    ViewRect.size.height =
    CGRectGetMinY(frame) - ViewRect.origin.y;
    [self.view setFrame:ViewRect];
    
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    _labCommentId.alpha = 0;//开始编辑时
    if ([_strIndexPath isEqualToString:@"1"]) {
        
    }else{
        NSIndexPath *index = [NSIndexPath indexPathForRow:0 inSection:0];
        [self.tableView cellForRowAtIndexPath:index];
        HRTimeLineModel *timeLineModel = self.dataArray[index.row];
        Active *model = [Active getActiveWithDictionary:(NSDictionary *)timeLineModel.active];
        _selectIndexPath = index;
        _trystId = model.trystId;
        _CircleId = [NSString stringWithFormat:@"%ld",model.circleId];
    }

 
    return YES;
}
@end
